<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="植株编号" prop="plantNumber">
        <el-input
          v-model="queryParams.plantNumber"
          placeholder="请输入植株编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="植株所在区块" prop="blockNumber">
        <el-input
          v-model="queryParams.blockNumber"
          placeholder="请输入植株所在区块"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="采样日期" prop="samplingDate">
        <el-date-picker clearable
          v-model="queryParams.samplingDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择采样日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="创建时间" prop="createTime">
        <el-date-picker clearable
          v-model="queryParams.createTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择创建时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="株高" prop="height">
        <el-input
          v-model="queryParams.height"
          placeholder="请输入株高"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主茎叶总面积" prop="mainLeafArea">
        <el-input
          v-model="queryParams.mainLeafArea"
          placeholder="请输入主茎叶总面积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="剩余叶总面积" prop="remainingLeafArea">
        <el-input
          v-model="queryParams.remainingLeafArea"
          placeholder="请输入剩余叶总面积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="全叶叶面积" prop="totalLeafArea">
        <el-input
          v-model="queryParams.totalLeafArea"
          placeholder="请输入全叶叶面积"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="主茎叶数量" prop="mainLeafCount">
        <el-input
          v-model="queryParams.mainLeafCount"
          placeholder="请输入主茎叶数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="剩余叶数量" prop="remainingLeafCount">
        <el-input
          v-model="queryParams.remainingLeafCount"
          placeholder="请输入剩余叶数量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="叶总数" prop="leafCount">
        <el-input
          v-model="queryParams.leafCount"
          placeholder="请输入叶总数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="叶鲜重" prop="leafFreshWeight">
        <el-input
          v-model="queryParams.leafFreshWeight"
          placeholder="请输入叶鲜重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="茎鲜重" prop="stemFreshWeight">
        <el-input
          v-model="queryParams.stemFreshWeight"
          placeholder="请输入茎鲜重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="蕾鲜重" prop="budFreshWeight">
        <el-input
          v-model="queryParams.budFreshWeight"
          placeholder="请输入蕾鲜重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铃鲜重" prop="bollFreshWeight">
        <el-input
          v-model="queryParams.bollFreshWeight"
          placeholder="请输入铃鲜重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="根鲜重" prop="rootFreshWeight">
        <el-input
          v-model="queryParams.rootFreshWeight"
          placeholder="请输入根鲜重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="叶干重" prop="leafDryWeight">
        <el-input
          v-model="queryParams.leafDryWeight"
          placeholder="请输入叶干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="茎干重" prop="stemDryWeight">
        <el-input
          v-model="queryParams.stemDryWeight"
          placeholder="请输入茎干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="蕾干重" prop="budDryWeight">
        <el-input
          v-model="queryParams.budDryWeight"
          placeholder="请输入蕾干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铃干重" prop="bollDryWeight">
        <el-input
          v-model="queryParams.bollDryWeight"
          placeholder="请输入铃干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="根干重" prop="rootDryWeight">
        <el-input
          v-model="queryParams.rootDryWeight"
          placeholder="请输入根干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="棉壳干重" prop="cottonShellDryWeight">
        <el-input
          v-model="queryParams.cottonShellDryWeight"
          placeholder="请输入棉壳干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="棉絮干重" prop="battDryWeight">
        <el-input
          v-model="queryParams.battDryWeight"
          placeholder="请输入棉絮干重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="比叶重" prop="specificLeafWeight">
        <el-input
          v-model="queryParams.specificLeafWeight"
          placeholder="请输入比叶重"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="叶面积指数LAI" prop="lai">
        <el-input
          v-model="queryParams.lai"
          placeholder="请输入叶面积指数LAI"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="铃数" prop="bolls">
        <el-input
          v-model="queryParams.bolls"
          placeholder="请输入铃数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="吐絮数" prop="openings">
        <el-input
          v-model="queryParams.openings"
          placeholder="请输入吐絮数"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="生物量" prop="biomass">
        <el-input
          v-model="queryParams.biomass"
          placeholder="请输入生物量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="叶氮浓度" prop="leafNConcentration">
        <el-input
          v-model="queryParams.leafNConcentration"
          placeholder="请输入叶氮浓度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="冠层氮密度" prop="canopyNDensity">
        <el-input
          v-model="queryParams.canopyNDensity"
          placeholder="请输入冠层氮密度"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="氮含量" prop="nitrogenContent">
        <el-input
          v-model="queryParams.nitrogenContent"
          placeholder="请输入氮含量"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="棉花品种" prop="variety">
        <el-input
          v-model="queryParams.variety"
          placeholder="请输入棉花品种"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="最后修改时间" prop="lastEditTime">
        <el-date-picker clearable
          v-model="queryParams.lastEditTime"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="请选择最后修改时间">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="备注" prop="description">
        <el-input
          v-model="queryParams.description"
          placeholder="请输入备注"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['vbze:plant:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['vbze:plant:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['vbze:plant:remove']"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="info"
          plain
          icon="el-icon-upload2"
          size="mini"
          @click="handleImport"
          v-hasPermi="['vbze:plant:import']"
        >导入</el-button>
      </el-col>



      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['vbze:plant:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="plantList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="植株id" align="center" prop="id" />
      <el-table-column label="植株编号" align="center" prop="plantNumber" />
      <el-table-column label="植株所在区块" align="center" prop="blockNumber" />
      <el-table-column label="采样日期" align="center" prop="samplingDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.samplingDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="株高" align="center" prop="height" />
      <el-table-column label="主茎叶总面积" align="center" prop="mainLeafArea" />
      <el-table-column label="剩余叶总面积" align="center" prop="remainingLeafArea" />
      <el-table-column label="全叶叶面积" align="center" prop="totalLeafArea" />
      <el-table-column label="主茎叶数量" align="center" prop="mainLeafCount" />
      <el-table-column label="剩余叶数量" align="center" prop="remainingLeafCount" />
      <el-table-column label="叶总数" align="center" prop="leafCount" />
      <el-table-column label="叶鲜重" align="center" prop="leafFreshWeight" />
      <el-table-column label="茎鲜重" align="center" prop="stemFreshWeight" />
      <el-table-column label="蕾鲜重" align="center" prop="budFreshWeight" />
      <el-table-column label="铃鲜重" align="center" prop="bollFreshWeight" />
      <el-table-column label="根鲜重" align="center" prop="rootFreshWeight" />
      <el-table-column label="叶干重" align="center" prop="leafDryWeight" />
      <el-table-column label="茎干重" align="center" prop="stemDryWeight" />
      <el-table-column label="蕾干重" align="center" prop="budDryWeight" />
      <el-table-column label="铃干重" align="center" prop="bollDryWeight" />
      <el-table-column label="根干重" align="center" prop="rootDryWeight" />
      <el-table-column label="棉壳干重" align="center" prop="cottonShellDryWeight" />
      <el-table-column label="棉絮干重" align="center" prop="battDryWeight" />
      <el-table-column label="比叶重" align="center" prop="specificLeafWeight" />
      <el-table-column label="叶面积指数LAI" align="center" prop="lai" />
      <el-table-column label="铃数" align="center" prop="bolls" />
      <el-table-column label="吐絮数" align="center" prop="openings" />
      <el-table-column label="生物量" align="center" prop="biomass" />
      <el-table-column label="叶氮浓度" align="center" prop="leafNConcentration" />
      <el-table-column label="冠层氮密度" align="center" prop="canopyNDensity" />
      <el-table-column label="氮含量" align="center" prop="nitrogenContent" />
      <el-table-column label="棉花品种" align="center" prop="variety" />
      <el-table-column label="备注" align="center" prop="description" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['vbze:plant:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['vbze:plant:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改植株管理对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="植株编号" prop="plantNumber">
          <el-input v-model="form.plantNumber" placeholder="请输入植株编号" />
        </el-form-item>
        <el-form-item label="植株所在区块" prop="blockNumber">
          <el-input v-model="form.blockNumber" placeholder="请输入植株所在区块" />
        </el-form-item>
        <el-form-item label="采样日期" prop="samplingDate">
          <el-date-picker clearable
            v-model="form.samplingDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择采样日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="创建人" prop="creator">
          <el-input v-model="form.creator" placeholder="请输入创建人" />
        </el-form-item>
        <el-form-item label="株高" prop="height">
          <el-input v-model="form.height" placeholder="请输入株高" />
        </el-form-item>
        <el-form-item label="主茎叶总面积" prop="mainLeafArea">
          <el-input v-model="form.mainLeafArea" placeholder="请输入主茎叶总面积" />
        </el-form-item>
        <el-form-item label="剩余叶总面积" prop="remainingLeafArea">
          <el-input v-model="form.remainingLeafArea" placeholder="请输入剩余叶总面积" />
        </el-form-item>
        <el-form-item label="全叶叶面积" prop="totalLeafArea">
          <el-input v-model="form.totalLeafArea" placeholder="请输入全叶叶面积" />
        </el-form-item>
        <el-form-item label="主茎叶数量" prop="mainLeafCount">
          <el-input v-model="form.mainLeafCount" placeholder="请输入主茎叶数量" />
        </el-form-item>
        <el-form-item label="剩余叶数量" prop="remainingLeafCount">
          <el-input v-model="form.remainingLeafCount" placeholder="请输入剩余叶数量" />
        </el-form-item>
        <el-form-item label="叶总数" prop="leafCount">
          <el-input v-model="form.leafCount" placeholder="请输入叶总数" />
        </el-form-item>
        <el-form-item label="叶鲜重" prop="leafFreshWeight">
          <el-input v-model="form.leafFreshWeight" placeholder="请输入叶鲜重" />
        </el-form-item>
        <el-form-item label="茎鲜重" prop="stemFreshWeight">
          <el-input v-model="form.stemFreshWeight" placeholder="请输入茎鲜重" />
        </el-form-item>
        <el-form-item label="蕾鲜重" prop="budFreshWeight">
          <el-input v-model="form.budFreshWeight" placeholder="请输入蕾鲜重" />
        </el-form-item>
        <el-form-item label="铃鲜重" prop="bollFreshWeight">
          <el-input v-model="form.bollFreshWeight" placeholder="请输入铃鲜重" />
        </el-form-item>
        <el-form-item label="根鲜重" prop="rootFreshWeight">
          <el-input v-model="form.rootFreshWeight" placeholder="请输入根鲜重" />
        </el-form-item>
        <el-form-item label="叶干重" prop="leafDryWeight">
          <el-input v-model="form.leafDryWeight" placeholder="请输入叶干重" />
        </el-form-item>
        <el-form-item label="茎干重" prop="stemDryWeight">
          <el-input v-model="form.stemDryWeight" placeholder="请输入茎干重" />
        </el-form-item>
        <el-form-item label="蕾干重" prop="budDryWeight">
          <el-input v-model="form.budDryWeight" placeholder="请输入蕾干重" />
        </el-form-item>
        <el-form-item label="铃干重" prop="bollDryWeight">
          <el-input v-model="form.bollDryWeight" placeholder="请输入铃干重" />
        </el-form-item>
        <el-form-item label="根干重" prop="rootDryWeight">
          <el-input v-model="form.rootDryWeight" placeholder="请输入根干重" />
        </el-form-item>
        <el-form-item label="棉壳干重" prop="cottonShellDryWeight">
          <el-input v-model="form.cottonShellDryWeight" placeholder="请输入棉壳干重" />
        </el-form-item>
        <el-form-item label="棉絮干重" prop="battDryWeight">
          <el-input v-model="form.battDryWeight" placeholder="请输入棉絮干重" />
        </el-form-item>
        <el-form-item label="比叶重" prop="specificLeafWeight">
          <el-input v-model="form.specificLeafWeight" placeholder="请输入比叶重" />
        </el-form-item>
        <el-form-item label="叶面积指数LAI" prop="lai">
          <el-input v-model="form.lai" placeholder="请输入叶面积指数LAI" />
        </el-form-item>
        <el-form-item label="铃数" prop="bolls">
          <el-input v-model="form.bolls" placeholder="请输入铃数" />
        </el-form-item>
        <el-form-item label="吐絮数" prop="openings">
          <el-input v-model="form.openings" placeholder="请输入吐絮数" />
        </el-form-item>
        <el-form-item label="生物量" prop="biomass">
          <el-input v-model="form.biomass" placeholder="请输入生物量" />
        </el-form-item>
        <el-form-item label="叶氮浓度" prop="leafNConcentration">
          <el-input v-model="form.leafNConcentration" placeholder="请输入叶氮浓度" />
        </el-form-item>
        <el-form-item label="冠层氮密度" prop="canopyNDensity">
          <el-input v-model="form.canopyNDensity" placeholder="请输入冠层氮密度" />
        </el-form-item>
        <el-form-item label="氮含量" prop="nitrogenContent">
          <el-input v-model="form.nitrogenContent" placeholder="请输入氮含量" />
        </el-form-item>
        <el-form-item label="棉花品种" prop="variety">
          <el-input v-model="form.variety" placeholder="请输入棉花品种" />
        </el-form-item>
        <el-form-item label="最后修改人" prop="lastEditor">
          <el-input v-model="form.lastEditor" placeholder="请输入最后修改人" />
        </el-form-item>
        <el-form-item label="最后修改时间" prop="lastEditTime">
          <el-date-picker clearable
            v-model="form.lastEditTime"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="请选择最后修改时间">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="备注" prop="description">
          <el-input v-model="form.description" placeholder="请输入备注" />
        </el-form-item>
        <el-divider content-position="center">叶片管理信息</el-divider>
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button type="primary" icon="el-icon-plus" size="mini" @click="handleAddLeaf">添加</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button type="danger" icon="el-icon-delete" size="mini" @click="handleDeleteLeaf">删除</el-button>
          </el-col>
        </el-row>
        <el-table :data="leafList" :row-class-name="rowLeafIndex" @selection-change="handleLeafSelectionChange" ref="leaf">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="序号" align="center" prop="index" width="50"/>
          <el-table-column label="叶位" prop="leafPlace" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.leafPlace" placeholder="请输入叶位" />
            </template>
          </el-table-column>
          <el-table-column label="叶面积" prop="leafArea" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.leafArea" placeholder="请输入叶面积" />
            </template>
          </el-table-column>
          <el-table-column label="叶干重" prop="leafDryWeight" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.leafDryWeight" placeholder="请输入叶干重" />
            </template>
          </el-table-column>
          <el-table-column label="叶片氮含量" prop="leafNitrogenContent" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.leafNitrogenContent" placeholder="请输入叶片氮含量" />
            </template>
          </el-table-column>
          <el-table-column label="叶绿素a含量" prop="chlorophyllAContent" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.chlorophyllAContent" placeholder="请输入叶绿素a含量" />
            </template>
          </el-table-column>
          <el-table-column label="叶绿素b含量" prop="chlorophyllBContent" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.chlorophyllBContent" placeholder="请输入叶绿素b含量" />
            </template>
          </el-table-column>
          <el-table-column label="叶绿素a+b含量" prop="chlorophyllABContent" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.chlorophyllABContent" placeholder="请输入叶绿素a+b含量" />
            </template>
          </el-table-column>
          <el-table-column label="测量日期" prop="measurementDate" width="240">
            <template slot-scope="scope">
              <el-date-picker clearable v-model="scope.row.measurementDate" type="date" value-format="yyyy-MM-dd" placeholder="请选择测量日期" />
            </template>
          </el-table-column>
          <el-table-column label="棉花品种" prop="variety" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.variety" placeholder="请输入棉花品种" />
            </template>
          </el-table-column>
          <el-table-column label="叶片备注" prop="description" width="150">
            <template slot-scope="scope">
              <el-input v-model="scope.row.description" placeholder="请输入叶片备注" />
            </template>
          </el-table-column>
        </el-table>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>



    <!-- 导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag
      >
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的植株数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>


  </div>
</template>

<script>
import { listPlant, getPlant, delPlant, addPlant, updatePlant } from "@/api/vbze/plant";
import { getToken } from '@/utils/auth'

export default {
  name: "Plant",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 子表选中数据
      checkedLeaf: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 植株管理表格数据
      plantList: [],
      // 叶片管理表格数据
      leafList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,

      // 导入参数
      upload: {
        // 是否显示弹出层（导入）
        open: false,
        // 弹出层标题（导入）
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的地块数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/vbze/plant/importData"
      },




      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        plantNumber: null,
        blockNumber: null,
        samplingDate: null,
        createTime: null,
        height: null,
        mainLeafArea: null,
        remainingLeafArea: null,
        totalLeafArea: null,
        mainLeafCount: null,
        remainingLeafCount: null,
        leafCount: null,
        leafFreshWeight: null,
        stemFreshWeight: null,
        budFreshWeight: null,
        bollFreshWeight: null,
        rootFreshWeight: null,
        leafDryWeight: null,
        stemDryWeight: null,
        budDryWeight: null,
        bollDryWeight: null,
        rootDryWeight: null,
        cottonShellDryWeight: null,
        battDryWeight: null,
        specificLeafWeight: null,
        lai: null,
        bolls: null,
        openings: null,
        biomass: null,
        leafNConcentration: null,
        canopyNDensity: null,
        nitrogenContent: null,
        variety: null,
        lastEditTime: null,
        description: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        plantNumber: [
          { required: true, message: "植株编号不能为空", trigger: "blur" }
        ],
        blockNumber: [
          { required: true, message: "植株所在区块不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询植株管理列表 */
    getList() {
      this.loading = true;
      listPlant(this.queryParams).then(response => {
        this.plantList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        plantNumber: null,
        blockNumber: null,
        samplingDate: null,
        creator: null,
        createTime: null,
        height: null,
        mainLeafArea: null,
        remainingLeafArea: null,
        totalLeafArea: null,
        mainLeafCount: null,
        remainingLeafCount: null,
        leafCount: null,
        leafFreshWeight: null,
        stemFreshWeight: null,
        budFreshWeight: null,
        bollFreshWeight: null,
        rootFreshWeight: null,
        leafDryWeight: null,
        stemDryWeight: null,
        budDryWeight: null,
        bollDryWeight: null,
        rootDryWeight: null,
        cottonShellDryWeight: null,
        battDryWeight: null,
        specificLeafWeight: null,
        lai: null,
        bolls: null,
        openings: null,
        biomass: null,
        leafNConcentration: null,
        canopyNDensity: null,
        nitrogenContent: null,
        variety: null,
        lastEditor: null,
        lastEditTime: null,
        description: null
      };
      this.leafList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加植株管理";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getPlant(id).then(response => {
        this.form = response.data;
        this.leafList = response.data.leafList;
        this.open = true;
        this.title = "修改植株管理";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          this.form.leafList = this.leafList;
          if (this.form.id != null) {
            updatePlant(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPlant(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除植株管理编号为"' + ids + '"的数据项？').then(function() {
        return delPlant(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
	/** 叶片管理序号 */
    rowLeafIndex({ row, rowIndex }) {
      row.index = rowIndex + 1;
    },
    /** 叶片管理添加按钮操作 */
    handleAddLeaf() {
      let obj = {};
      obj.leafPlace = "";
      obj.leafArea = "";
      obj.leafDryWeight = "";
      obj.leafNitrogenContent = "";
      obj.chlorophyllAContent = "";
      obj.chlorophyllBContent = "";
      obj.chlorophyllABContent = "";
      obj.measurementDate = "";
      obj.variety = "";
      obj.description = "";
      this.leafList.push(obj);
    },
    /** 叶片管理删除按钮操作 */
    handleDeleteLeaf() {
      if (this.checkedLeaf.length == 0) {
        this.$modal.msgError("请先选择要删除的叶片管理数据");
      } else {
        const leafList = this.leafList;
        const checkedLeaf = this.checkedLeaf;
        this.leafList = leafList.filter(function(item) {
          return checkedLeaf.indexOf(item.index) == -1
        });
      }
    },
    /** 复选框选中数据 */
    handleLeafSelectionChange(selection) {
      this.checkedLeaf = selection.map(item => item.index)
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('vbze/plant/export', {
        ...this.queryParams
      }, `plant_${new Date().getTime()}.xlsx`)
    },


    /** 导入按钮操作 */
    handleImport() {
      this.upload.title = "植株导入";
      this.upload.open = true;
    },
    /** 下载模板操作 */
    importTemplate() {
      this.download('vbze/plant/importTemplate', {
      }, `plant_template_${new Date().getTime()}.xlsx`)
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert("<div style='overflow: auto;overflow-x: hidden;max-height: 70vh;padding: 10px 20px 0;'>" + response.msg + "</div>", "导入结果", { dangerouslyUseHTMLString: true });
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
